﻿<div [@routerTransition]>
    <div class="row margin-bottom-5">
        <div class="col-xs-6">
            <div class="page-head">
                <div class="page-title">
                    <h1>
                        <span>{{l("Roles")}}</span> <small>{{l("RolesHeaderInfo")}}</small>
                    </h1>
                </div>
            </div>
        </div>
        <div class="col-xs-6 text-right">
            <button (click)="createRole()" *ngIf="isGranted('Pages.Administration.Roles.Create')" class="btn btn-primary blue"><i class="fa fa-plus"></i> {{l("CreateNewRole")}}</button>
        </div>
    </div>

    <div class="portlet light margin-bottom-0">
        <div class="portlet-title portlet-title-filter">
            <div class="inputs inputs-full-width">
                <div class="portlet-input">
                    <form>
                        <div class="row">
                            <div class="col-xs-6">
                                <permission-combo [(selectedPermission)]="selectedPermission"></permission-combo>
                            </div>
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <button name="RefreshButton" class="btn blue" (click)="getRoles()"><i class="fa fa-refresh"></i> {{l('Refresh')}}</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="portlet-body">
            <!--<Primeng-Datatable-Start>-->
            <div class="primeng-datatable-container" [busyIf]="primengDatatableHelper.isLoading">
                <p-dataTable #dataTable
                             (onLazyLoad)="getRoles()"
                             [value]="primengDatatableHelper.records"
                             rows="{{primengDatatableHelper.defaultRecordsCountPerPage}}"
                             [paginator]="false"
                             [lazy]="true"
                             emptyMessage="{{l('NoData')}}"
                             [responsive]="primengDatatableHelper.isResponsive">
                    <p-footer>
                        {{l('TotalRecordsCount', primengDatatableHelper.totalRecordsCount)}}
                    </p-footer>

                    <p-column field="" 
                              header="{{l('Actions')}}"
                              [sortable]="false" 
                              styleClass="width-percent-15"
                              [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">
                        <ng-template let-record="rowData" pTemplate="body">
                            <div class="btn-group dropdown">
                                <button class="dropdown-toggle btn btn-xs btn-primary blue"
                                        data-toggle="dropdown"
                                        tooltip="{{l('Actions')}}"
                                        aria-haspopup="true"
                                        aria-expanded="false">
                                    <i class="fa fa-cog"></i><span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a *ngIf="permission.isGranted('Pages.Administration.Roles.Edit')"
                                           (click)="createOrEditRoleModal.show(record.id)">{{l('Edit')}}</a>
                                    </li>
                                    <li>
                                        <a *ngIf="!record.isStatic && permission.isGranted('Pages.Administration.Roles.Delete')"
                                           (click)="deleteRole(record)">{{l('Delete')}}</a>
                                    </li>
                                </ul>
                            </div>
                        </ng-template>
                    </p-column>
                    <p-column field="displayName" header="{{l('RoleName')}}" [sortable]="false">
                        <ng-template let-record="rowData" pTemplate="body">
                            <span>
                                {{record.displayName}}
                                <span *ngIf="record.isStatic" 
                                      class="label label-info margin-right-5 margin-left-5" 
                                      data-toggle="tooltip" 
                                      title="{{l('StaticRole_Tooltip')}}" 
                                      data-placement="top">{{l('Static')}} 
                                </span> 
                                <span *ngIf="record.isDefault"
                                      class="label label-default"
                                      data-toggle="tooltip"
                                      title="{{l('DefaultRole_Description')}}"
                                      data-placement="top">
                                    {{l('Default')}}
                                </span>
                            </span>
                        </ng-template>
                    </p-column>

                    <p-column field="creationTime" header="{{l('CreationTime')}}" [sortable]="false">
                        <ng-template let-record="rowData" pTemplate="body">
                            {{record.creationTime | momentFormat:'L'}}
                        </ng-template>
                    </p-column>

                </p-dataTable>

            </div>
            <!--<Primeng-Datatable-End>-->
        </div>
    </div>

    <createOrEditRoleModal #createOrEditRoleModal (modalSave)="getRoles()"></createOrEditRoleModal>
</div>